package com.kaifamiao.map;

import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class TestPairs {

    public static void main(String[] args) {

        Pairs<String,Integer> p = new Pairs<>();
        System.out.println( p.isEmpty() + " , " + p.size() );

        System.out.println( p.put( "牛肉面", 10 ) );
        System.out.println( p.put( "小菜", 3 ) );
        System.out.println( p );

        System.out.println( p.put( "小菜", 2 ) );
        System.out.println( p );

        System.out.println( p.containsKey( "卤蛋" ) );
        System.out.println( p.containsKey( "牛肉面" ) );

        System.out.println( p );

        Set<String> keys = p.keySet();
        for ( String k : keys ) {
            System.out.println( k );
        }

        Collection<Integer> values = p.values();
        for ( Integer v : values ) {
            System.out.println( v );
        }

        // Set 是 Collection 的子接口
        Set< Map.Entry<String,Integer> > entries = p.entrySet();

        Iterator< Map.Entry<String,Integer> > itor = entries.iterator();

        while ( itor.hasNext() ) {
            Map.Entry<String,Integer> entry = itor.next();
            System.out.println( entry.getKey() + ", " + entry.getValue() );
        }

    }

}
